package com.tjp.eight.ui.fragment.detailjb;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.tjp.eight.R;

import java.util.ArrayList;

/**
 * Created by Administrator on 2017/4/10.
 */
public class DetailJBAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context context;
    private ArrayList<DetailJBItem> models;

    public DetailJBAdapter(Context context) {
        this.context = context;
        models = new ArrayList<>();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_detail_jb, parent, false);
        return new DetailJBViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (models.get(position).type == 1){
            ((DetailJBViewHolder) holder).tv_money_in.setTextColor(Color.parseColor("#ff363e"));
            ((DetailJBViewHolder) holder).tv_money_in.setText(""+models.get(position).money);
            ((DetailJBViewHolder) holder).tv_money_type.setText("收入");
        }else {
            ((DetailJBViewHolder) holder).tv_money_in.setTextColor(Color.parseColor("#000000"));
            ((DetailJBViewHolder) holder).tv_money_in.setText(""+models.get(position).money);
            ((DetailJBViewHolder) holder).tv_money_type.setText("支出");
        }
        ((DetailJBViewHolder) holder).tv_time.setText(models.get(position).time);
        ((DetailJBViewHolder) holder).tv_money_reset.setText(models.get(position).money_rest);
        ((DetailJBViewHolder) holder).tv_money_in_tips.setText(models.get(position).detail);
    }

    @Override
    public int getItemCount() {
        return models.size();
    }

    public void addData(ArrayList<DetailJBItem> list) {
        if (list == null || list.isEmpty()) return;
        int index = models.size();
        for (DetailJBItem item : list) {
            models.add(item);
        }
       // notifyItemRangeInserted(index, getItemCount());
        notifyDataSetChanged();
    }

    class DetailJBViewHolder extends RecyclerView.ViewHolder {
        TextView tv_time;
        TextView tv_money_type;
        TextView tv_money_in;
        TextView tv_money_in_tips;
        TextView tv_money_reset;
        public DetailJBViewHolder(View v) {
            super(v);
            tv_time = (TextView) v.findViewById(R.id.tv_time);
            tv_money_type = (TextView) v.findViewById(R.id.tv_money_type);
            tv_money_in = (TextView) v.findViewById(R.id.tv_money_in);
            tv_money_in_tips = (TextView) v.findViewById(R.id.tv_money_in_tips);
            tv_money_reset = (TextView) v.findViewById(R.id.tv_money_reset);
        }
    }
}
